package com.csesteel.crm.util;

import com.csesteel.crm.domain.CrmRole;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2015/4/27 0027.
 */
public class WebUtil {
    public static void responseToJson( HttpServletResponse response, Object obj ){

        response.setContentType("text/html;charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("X-Frame-Options", "SAMEORIGIN");

        try {

            Gson gson = new Gson();
            response.getWriter().write( gson.toJson(obj) );
            response.getWriter().flush();

        } catch (IOException e) {
            e.printStackTrace();

        }

    }

    public static void responseToJsonString( HttpServletResponse response, String string){

        response.setContentType("text/html;charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("X-Frame-Options", "SAMEORIGIN");

        try {

            response.getWriter().write( string.toString() );
            response.getWriter().flush();

        } catch (IOException e) {
            e.printStackTrace();

        }

    }
}
